package com.bianyuanren.web.controller.app;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.bianyuanren.common.annotation.Log;
import com.bianyuanren.common.enums.BusinessType;
import com.bianyuanren.system.domain.SysCountry;
import com.bianyuanren.system.service.ISysCountryService;
import com.bianyuanren.common.core.controller.BaseController;
import com.bianyuanren.common.core.domain.AjaxResult;
import com.bianyuanren.common.utils.poi.ExcelUtil;
import com.bianyuanren.common.core.page.TableDataInfo;

/**
 *
 * 设置国家信息
 *
 * @author bianyuanren
 * @date 2020-03-16
 */
@Controller
@RequestMapping("/app/country")
public class AppCountryController extends BaseController
{
    private String prefix = "app/country";

    @Autowired
    private ISysCountryService sysCountryService;

    @RequiresPermissions("system:country:view")
    @GetMapping()
    public String country()
    {
        return prefix + "/country";
    }

    /**
     * 查询【请填写功能名称】列表
     */
    @RequiresPermissions("system:country:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysCountry sysCountry)
    {
        startPage();
        List<SysCountry> list = sysCountryService.selectSysCountryList(sysCountry);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @RequiresPermissions("system:country:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysCountry sysCountry)
    {
        List<SysCountry> list = sysCountryService.selectSysCountryList(sysCountry);
        ExcelUtil<SysCountry> util = new ExcelUtil<SysCountry>(SysCountry.class);
        return util.exportExcel(list, "country");
    }

    /**
     * 新增【请填写功能名称】
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存【请填写功能名称】
     */
    @RequiresPermissions("system:country:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysCountry sysCountry)
    {
        return toAjax(sysCountryService.insertCountry(sysCountry));
    }

    /**
     * 修改【请填写功能名称】
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SysCountry sysCountry = sysCountryService.selectSysCountryById(id);
        mmap.put("sysCountry", sysCountry);
        return prefix + "/edit";
    }

    /**
     * 修改保存【请填写功能名称】
     */
    @RequiresPermissions("system:country:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysCountry sysCountry)
    {
        return toAjax(sysCountryService.updateCountry(sysCountry));
    }

    /**
     * 删除【请填写功能名称】
     */
    @RequiresPermissions("system:country:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysCountryService.deleteCountryByIds(ids));
    }

    @RequiresPermissions("system:country:appList")
    @PostMapping("/appList")
    @ResponseBody
    public AjaxResult appList(SysCountry sysCountry)
    {
        List<SysCountry> list = sysCountryService.selectSysCountryList(sysCountry);
        return AjaxResult.success(list);
    }
}
